import { GOOD_TYPE } from '@/const/index.js'

/** 选择sku */
export const selectSkuMixin = {
	data() {
		return {
			GOOD_TYPE,
			classification: {
				"spec_item_name": '',
				"shop_price": '',
			},
			buyNum: 1, // 购买数量
			popupShow1653961165769: false, // 是否显示sku
			goodData: {},
			spec_list: [],
			sku_list: [],
		}
	},
	methods: {
		// 选择规格
		selectSpec(k, key) {
			this.spec_list[k].child.forEach((v, k) => {
				v.isSelect = false;
			})
			this.spec_list[k].child[key].isSelect = true;
			this.$forceUpdate();
			let specs = '';
			this.spec_list.forEach((v, k) => {
				if (v.child.length > 0) {
					v.child.forEach((v1, k1) => {
						if (v1.isSelect) {
							specs += v.child[k1].id + '_';
						}
					})
				}
			})
			specs = specs.substring(0, specs.length - 1);
			for (var i in this.sku_list) {
				if (specs == this.sku_list[i].spec_item_id) {
					this.classification = this.sku_list[i];
					console.log(this.classification);
				}
			}
		},
		setSkuList(info = {}) {
			this.goodData = info;
			this.spec_list = this.goodData.goods_spec || [];
			this.sku_list = this.goodData.goods_sku || [];
		},
		// 打开规格
		openSpec() {
			// this.sku_open_type = sku_open_type;
			// if (this.classification.shop_price) return;
			if (this.classification.sku_id) this.popupShow1653961165769 = true;
			else if (this.spec_list.length > 0) {
				this.popupShow1653961165769 = true;
				let specs = '';
				this.spec_list.forEach((v, k) => {
					if (v.child.length > 0) {
						v.child.forEach((v1, k1) => {
							if (k1 == 0) {
								v1.isSelect = true;
								specs += v1.id + '_';
							} else {
								v1.isSelect = false;
							}
						})
					}
				})
				specs = specs.substring(0, specs.length - 1);
				// console.log(specs);
				for (var i in this.sku_list) {
					if (specs == this.sku_list[i].spec_item_id) {
						this.classification = this.sku_list[i];
						console.log(this.classification);
					}
				}
			} else {
				this.$message.info('暂无规格可以选择');
			}
		},
	}
}